function setData(context, param) {
  return new Promise(resolve => {
    context.setData(param, () => {
      resolve()
    })
  })
}

function getImageInfo(param) {
  return new Promise((resolve, reject) => {
    my.getImageInfo({
      ...param,
      success: res => {
        resolve(res)
      },
      fail: error => {
        reject(error)
      }
    })
  })
}

function chooseImage(param) {
  return new Promise((resolve, reject) => {
    my.chooseImage({
      ...param,
      success: res => {
        resolve(res)
      },
      fail: error => {
        reject(error)
      }
    })
  })
}

function putImageDataToCanvas(canvasContext, param) {
  return new Promise(resolve => {
    canvasContext.putImageData({
      ...param,
      success: () => {
        resolve()
      }
    })
  })
}

function toTempFilePathFromCanvas(canvasContext, param = {}) {
  return new Promise(resolve => {
    canvasContext.toTempFilePath({
      ...param,
      success: res => {
        resolve(res.filePath)
      }
    })
  })
}

module.exports = {
  setData,
  getImageInfo,
  chooseImage,
  putImageDataToCanvas,
  toTempFilePathFromCanvas
}
